<?php

namespace App\Model\User;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

use Illuminate\Database\Eloquent\Model;

class User extends Authenticatable
{
    use HasApiTokens, Notifiable;
    /**
     * 与模型关联的数据表。
     *
     * @var string
     */
    protected $table = 'users';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'username', 'password',
    ];
    protected $hidden = ['password'];

    /**
     * @param $username
     * @return mixed
     */
    public function findForPassport($username)
    {
        return \App\Model\User\User::normal()
            ->where('username', $username)
            ->first();
    }

    public function scopeNormal($query)
    {
        return $query->where('is_active', 1);
    }

    public function groups()
    {
        return $this->belongsToMany('App\Model\User\AuthGroup', 'auth_user_groups', 'user_id', 'group_id')/*->wherePivot('group_id')*/;
    }
    public function meal_supplement_balance()
    {
        return $this->hasOne('App\Model\Order\MealSupplementBalance');
    }
}
